package com.ershijin.authserver.config;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

@EnableWebSecurity
public class DefaultSecurityConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
//        String encodingId = "MY";
//        Map<String, PasswordEncoder> encoders = new HashMap<>();
//        encoders.put("MY", new MyMd5PasswordEncoder());
//        encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
//        return new DelegatingPasswordEncoder(encodingId, encoders);
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }


    @Bean
    SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests(authorizeRequests ->
          authorizeRequests
                  .anyRequest().authenticated()
        )
          .formLogin(withDefaults());

        return http.build();
    }

}
